package com.woniuxy.creditsystem.mortgagemag.controller;


import com.github.pagehelper.PageInfo;
import com.woniuxy.creditsystem.common.bean.*;
import com.woniuxy.creditsystem.common.bean.ResultMsg;
import com.woniuxy.creditsystem.mortgagemag.service.IHouseService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("/house")
@RestController
public class HouseController {

    @Resource
    private IHouseService houseServiceImpl;


    @RequestMapping(value="/page",produces = {"application/json;charset=utf-8"})
    public TableResult<HouseInfo> findAllByParams(Integer pageNum, Integer pageSize, HouseFind houseFind){
        System.out.println(houseFind.getHousingType());
        System.out.println("....");
        System.out.println(pageNum);
        System.out.println(pageSize);
        PageInfo<HouseInfo> pageInfo = houseServiceImpl.findAllByParams( pageNum,pageSize,houseFind);
        System.out.println(pageInfo);

        return new TableResult<HouseInfo>(pageInfo.getTotal(),pageInfo.getList());
    }

    @PutMapping(value="/{id}",produces = {"application/json;charset=utf-8"})
    public ResultMsg updateHouse(HouseInfo houseInfo, @PathVariable("id") Long id){
        System.out.println(id);
        System.out.println(houseInfo);
        ResultMsg resultMsg = new ResultMsg(200,"新增成功",null);
        houseServiceImpl.updateHouse(houseInfo);
        return resultMsg;
    }


    @RequestMapping(value="/more",produces = {"application/json;charset=utf-8"})
    public ResultMsg saveHouse(HouseInfo houseInfo){

        System.out.println("添加");
        ResultMsg resultMsg = new ResultMsg(200,"新增成功",null);
        CustomerInfo customerInfo =new CustomerInfo();
        customerInfo.setId(1);
        houseInfo.setCustomerInfo(customerInfo);
        houseServiceImpl.saveHouseInfo(houseInfo);
        return resultMsg;
    }
}
